<template>
	<view class="info">
		<view class="flex flex-jc-sb flex-ai-c">
			<view>微信账号</view>
			<u-input input-align="right" @blur="(e) => onBlur(e,'wechat_no')" v-model="info.detail.wechat_no" />
		</view>
		<view class="flex flex-jc-sb flex-ai-c" style="margin: 30rpx 0;position: relative;">
			<view>交换金额</view>
			<u-input input-align="right" type="digit" @blur="(e) => onBlur(e,'exchange_amount')" v-model="info.detail.exchange_amount" style="margin-right: 50rpx;" /> <text style="position: absolute;right: 0;">元</text>
		</view>
		<view class="flex flex-jc-sb flex-ai-c">
			<view>交换状态</view>
			<view>
				<u-switch @change="(e) => switchStatus(e,'exchange_status')" v-model="info.detail.exchange_status" :active-value="1" :inactive-value="0" active-color="#000"></u-switch>
			</view>
		</view>
		<!-- <view class="flex flex-jc-sb flex-ai-c" style="margin-top: 30rpx;">
			<view>是否参与排名</view>
			<view>
				<u-switch @change="(e) => switchStatus(e,'is_rank')" v-model="info.detail.is_rank" :active-value="1" :inactive-value="0" active-color="#000"></u-switch>
			</view>
		</view> -->
	</view>
	<view style="margin: 56rpx 20rpx;">
		<view class="font-bold font-26">
			设置说明
		</view>
		<view class="mt-20">
			<rich-text :nodes="info.nodes"></rich-text>
		</view>
	</view>
</template>

<script  lang="ts" setup>
	import user from '../../api/user'
	import common from '../../api/common.js'
	import {
		reactive
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	let info: any = reactive({
		detail: {},
		newUserinfo: {},
		nodes: ''
	})
	const getMemberInfo = async () => {
		const res = await user.getMemberInfo()
		info.detail = res.data
		info.newUserinfo = JSON.parse(JSON.stringify(res.data))
	}
	const onBlur = async (e : any, type : string) => {
		if(type == 'exchange_amount' && info.detail.exchange_amount < 0) return uni.showToast({
			title: '请输入正确金额',
			icon: 'none'
		})
		if (info.newUserinfo[type] == e) return
		const res = await user.editMemberInfo({
			id: info.detail.id,
			[type]: info.detail[type]
		})
		
	}
	const switchStatus = async (e: any, type: string) => {
		const res = await user.editMemberInfo({
			id: info.detail.id,
			[type]: e
		})
		if(res.code !== 200) {
			info.detail[type] = e == 0 ? 1 : 0
		}
	}
	const sysConfig = async () => {
		const res = await common.sysConfig()
		info.nodes = res.data.private_desc
	}
	onLoad(() => {
		getMemberInfo()
		sysConfig()
	})
</script>

<style>
	page{
		background: #F8F8F8;
	}
</style>
<style lang="scss" scoped>
	:deep(.u-input){
		
		
	}
	.info{
		margin-top: 20rpx;
		background: #fff;
		padding: 30rpx;
	}
</style>